﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Sylvain.Manager;
using Sylvain.Model;
using System.IO;

public partial class PastPublications : System.Web.UI.Page
{
    /// <summary>
    /// Display content of the Page.
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            Session[AppSession.SearchText.ToString()] = (this.Page.Master as SiteMaster).GetSearchText.Trim();
        }
        if (!IsPostBack)
        {
            ISylvainManager objManager = new SylvainManager();
            int pageId = objManager.GetPageId("past_ publications");
            //string pageContent = objManager.GetPageContent(pageId);
            //if (pageContent.Length > 0)
            //{

                //mainDiv.InnerHtml = pageContent;
                BindPublicationsGrid();
            //}

        }
    }

    protected void BindPublicationsGrid()
    {
        ISylvainManager objManager = new SylvainManager();
        grvPublications.DataSource = objManager.GetAllPublications();
        grvPublications.DataBind();

    }

    protected void grvPublications_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        Publication row = (Publication)e.Row.DataItem;
        if (row != null)
        {
            HyperLink lnk = (HyperLink)e.Row.FindControl("hlnkPubFileName");
            HiddenField hid = (HiddenField)e.Row.FindControl("hidFileName");
            //Label lblDesc = (Label)e.Row.FindControl("lblDescription");

            //if (lblDesc != null)
            //{

            //}

            if (lnk != null && hid != null)
            {
                lnk.Visible = true;
                lnk.NavigateUrl = "~/PastPublicationDetails.aspx?id=" + hid.Value;
                //if (hid.Value != "")
                //{
                //    if (File.Exists(Server.MapPath("~/Publications/" + hid.Value)))
                //    {
                //        lnk.Visible = true;
                //        //lnk.NavigateUrl = "javascript:void(0)";// "~/Publications/" + hid.Value;
                //        lnk.Attributes.Add("onclick", "document.getElementById('light').style.display='block';document.getElementById('fade').style.display='block'");
                //    }
                //}

            }
        }
    }
}